package com.example.sensors;

import java.util.Map;

import android.hardware.SensorEvent;

import com.example.priorityobserver.Observable;
import com.example.priorityobserver.Observer;

public class Sensor_PhoneLock extends AbstractSensor implements
		Observer<Map<String, Object>> {
	public static final String NAME = "PHONE_LOCK";

	public Sensor_PhoneLock(AbstractSensor screenSensor) {
		screenSensor.registerObserver(this);
	}

	public void disableSensor() {
		super.disableSensor();
	}

	public void enableSensor() {
		super.enableSensor();
	}

	public String smallEventInsertion(String sensorName, SensorEvent arguments,
			String message) {
		// TODO Auto-generated method stub
		return null;
	}

	public String getSensorName() {
		return "PHONE_LOCK";
	}

	public void update(Observable<Map<String, Object>> observable,
			Map<String, Object> eventArgs) {
		if (eventArgs.get("eventType").equals("sensorInfoReceived")) {
			if (eventArgs.get("screenActivity").equals("OFF")) {
				Map<String, Object> args = initEventArgs();
				args.put("eventType", "sensorInfoReceived");
				args.put("phoneLock", "LOCKED");
				OnSensorChanged(args);
			}
			if (eventArgs.get("screenActivity").equals("ON")
					&& eventArgs.get("userActivity").equals("YES")) {
				Map<String, Object> args = initEventArgs();
				args.put("eventType", "sensorInfoReceived");
				args.put("phoneLock", "UNLOCKED");
				OnSensorChanged(args);
			}
		}
		// TODO: Sense the case when the phone gets locked but the screen is on.
	}
}
